package com.example.springbootusecase.controller;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONUtil;
import com.example.springbootusecase.bo.User;
import com.example.springbootusecase.bo.UserContextHolder;
import com.example.springbootusecase.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Think
 */
@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;
    @GetMapping("/query")
    public void query() {
        UserContextHolder.setUser(User
                        .builder()
                        .age(RandomUtil.randomInt(50)).build());
        log.info("UserController线程:{},user:{}",Thread.currentThread().getName(), JSONUtil.toJsonStr(UserContextHolder.getUser()));
        userService.getUser();
    }
}
